<template>
  <div class="app-container">
    <el-form>
      <el-card class="box-card" shadow="always" style="width: 100% ;height: 100px;margin-top: 5px">
        <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
          <el-form-item label="选择时间">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="box-card"  shadow="always" style="width: 100% ;height: 50px ;margin-top: 5px">
        <el-col :span="4">合计收入:{{cashIncome+zfbIncome-zfbRefund-cashRefund+'￥'}}</el-col>
      </el-card>
      <el-card class="box-card" shadow="always" style="width: 100% ;height: 50px;margin-top: 5px">
        <el-col :span="4">收支概况:</el-col>
        <el-col :span="4">总收入{{cashIncome+zfbIncome+'￥'}}</el-col>
        <el-col :span="4"style="color: red">总退费{{zfbRefund+cashRefund+'￥'}}</el-col>
      </el-card>
      <el-card class="box-card" shadow="always" style="width: 100% ;height: 50px;margin-top: 5px">
        <el-col :span="4">收入渠道:</el-col>
        <el-col :span="4">现金支付{{cashIncome+'￥'}}</el-col>
        <el-col :span="4">支付宝支付{{zfbIncome+'￥'}}</el-col>
        <el-col :span="4" style="color: red">现金退费{{zfbRefund+'￥'}}</el-col>
        <el-col :span="4" style="color: red">支付宝退费{{cashRefund+'￥'}}</el-col>
      </el-card>
      <el-col :span="8" >
        <el-card>
            <div ref="commandstats" style="height: 420px" />
        </el-card>
      </el-col>
      <el-col :span="8" >
        <el-card>
            <div ref="commandstats1" style="height: 420px" />
        </el-card>
      </el-col>
      <el-col :span="8" >
        <el-card>
            <div ref="commandstats2" style="height: 420px" />
        </el-card>
      </el-col>
    </el-form>
  </div>
</template>
<script>
  import { listTrade  } from "@/api/data/trade/trade";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import echarts from "echarts";
  export default {
    name: "User",
    components: { Treeselect },
    data() {
      return {
        // 遮罩层
        loading: true,

        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 用户表格数据
        cashIncome:0,
        zfbIncome:0,
        cashRefund:0,
        zfbRefund:0,
        // cache信息
        charts:"",
        opinion:["收入金额","退费金额"],
        opinionData: [],
        charts1:"",
        opinion1:["现金收入","支付宝收入"],
        opinionData1: [],
        charts2:"",
        opinion2:["现金退款","支付宝退款"],
        opinionData2: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        // 是否显示弹出层
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        //查询列表
        queryParams: {
        },
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",


        },
      };
    },
    created() {
      this.getList();

    },
    methods: {
      /** 查询用户列表 */
      getList() {
        this.loading = true;
        listTrade(this.addDateRange(this.queryParams,this.dateRange)).then(response => {
            this.cashIncome = response.data.cashIncome;
            this.zfbIncome = response.data.zfbIncome;
            this.cashRefund = response.data.cashRefund;
            this.zfbRefund = response.data.zfbRefund;
            this.loading = false;
            this.opinionData=[{name: "收入金额", value: this.cashIncome+this.zfbIncome},
                              {name: "退费金额", value: this.cashRefund+this.zfbRefund}],
            this.opinionData1=[{name: "现金收入", value: this.cashIncome},
                                {name: "支付宝收入", value: this.zfbIncome}],
            this.opinionData2=[{name: "现金退款", value: this.cashRefund},
                                {name: "支付宝退款", value: this.zfbRefund}],

            this.charts = echarts.init(this.$refs.commandstats, "macarons");
            this.charts1 = echarts.init(this.$refs.commandstats1, "macarons1");
            this.charts2 = echarts.init(this.$refs.commandstats2, "macarons2");
            this.charts.setOption({
              color: ['rgb(46,199,201)', 'rgb(182,162,222)'],
              tooltip: {
                trigger: "item",
                formatter: "{a}<br/>{b}:{c} ({d}%)"
              },
              legend: {
                bottom: 10,
                left: "center",
                data: this.opinion
              },
              series: [
                { name: "状态",
                  type: "pie",
                  roseType: "radius",
                  radius: ["5%","40%"],
                  center: ["50%", "50%"],
                  avoidLabelOverlap: false,
                  data: this.opinionData,
                  itemStyle: {
                    emphasis: {
                      shadowBlur: 10,
                      shadowOffsetX: 0,
                      shadowColor: "#79d2c0"
                    },
                  },
                }
              ]
            });
            this.charts1.setOption({
              color: ['rgb(46,199,201)', 'rgb(182,162,222)'],
              tooltip: {
                trigger: "item",
                formatter: "{a}<br/>{b}:{c} ({d}%)"
              },
              legend: {
                bottom: 10,
                left: "center",
                data: this.opinion1
              },
              series: [
                { name: "状态",
                  type: "pie",
                  roseType: "radius",
                  radius: ["5%","40%"],
                  center: ["50%", "50%"],
                  avoidLabelOverlap: false,
                  data: this.opinionData1,
                  itemStyle: {
                    emphasis: {
                      shadowBlur: 10,
                      shadowOffsetX: 0,
                      shadowColor: "#79d2c0"
                    },
                  },
                }
              ]
            });
            this.charts2.setOption({
              color: ['rgb(46,199,201)', 'rgb(182,162,222)'],
              tooltip: {
                trigger: "item",
                formatter: "{a}<br/>{b}:{c} ({d}%)"
              },
              legend: {
                bottom: 10,
                left: "center",
                data: this.opinion2
              },
              series: [
                { name: "状态",
                  type: "pie",
                  roseType: "radius",
                  radius: ["5%","40%"],
                  center: ["50%", "50%"],
                  avoidLabelOverlap: false,
                  data: this.opinionData2,
                  itemStyle: {
                    emphasis: {
                      shadowBlur: 10,
                      shadowOffsetX: 0,
                      shadowColor: "#79d2c0"
                    },
                  },
                }
              ]
            });
          }
        );
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
